package cn.sangyy.basic.controller;

import cn.sangyy.basic.service.ICosService;
import cn.sangyy.basic.utils.AjaxResult;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.multipart.MultipartFile;


/**
 * @author SangYY
 * @date: 2023/05/24/18:42
 */
@RestController
@RequestMapping("/txCos")
public class TxCosController {


    @Autowired
    private ICosService cosService;

    /**
    * @author Sangyy
    * 上传文件到Cos
    */
    @PostMapping
    public AjaxResult upload(MultipartFile file) throws Exception {
        String url = cosService.uploadImage(file);
        return AjaxResult.me().setResultObj(url);
    }

    /**
     * @author Sangyy
     * 从Cos中删除文件
     */
    @GetMapping("delete")
    public AjaxResult delete(@RequestParam("path") String path){
        cosService.deleteImage(path);
        return AjaxResult.me();
    }
}
